package o2o.dao.TO.sync;

import com.jinyou.utils.common.ValidateUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import o2o.cache.company.postman.PostTypeMemory;
import o2o.dao.PO.company.postman.PostTypeInfo;
import o2o.dao.PO.company.postman.ShopSignCompanyFeeInfo;

/**
 * @author Jahnke【1029777564@qq.com】
 * @ClassName ShopSignDeliverComMoneyTO
 * @Description: 商户签约配送公司的配送费信息
 * @date 2019/8/8 10:54
 * @Version 1.0
 */
@Data
@Accessors(chain = true)
public class ShopSignDeliverComMoneyTO {

    private Long postTypeId;
    private Double money;
    private Double companyShareRate;

    public ShopSignCompanyFeeInfo convert2Info(Long shopId, Long companyId) {
        PostTypeInfo postTypeInfo = PostTypeMemory.getInstance().getById(this.getPostTypeId());
        if (postTypeInfo != null) {
            ShopSignCompanyFeeInfo info = new ShopSignCompanyFeeInfo();
            info.setShopId(shopId).setCompanyId(companyId).setPostType(postTypeInfo.getType()).setPrice(money).setCreateTime(System.currentTimeMillis());
            if (ValidateUtil.isNotAbsDouble(companyShareRate)) {
                companyShareRate = 0.0d;
            }
            info.setCompanyShareRate(companyShareRate);
            return info;
        }
        return null;
    }
}
